package cn.chenchendemospringboot.order_demo.schdule;

import cn.chenchendemospringboot.order_demo.service.KafkaEventPublishService;
import cn.chenchendemospringboot.order_demo.service.impl.KafkaEventPublishServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


@Component
@EnableScheduling
@Slf4j
public class PublishSchedule {

    private final KafkaEventPublishServiceImpl kafkaEventPublishService;

    // 通过构造器注入 KafkaEventPublishServiceImpl
    public PublishSchedule(KafkaEventPublishServiceImpl kafkaEventPublishService) {
        this.kafkaEventPublishService = kafkaEventPublishService;
    }

    @Scheduled(fixedRate = 5000)
    public void publish() {
        log.info("EventPublishSchedule execute.");
        kafkaEventPublishService.publish();
    }
//    @Resource
//    KafkaEventPublishServiceImpl kafkaEventPublishService;
//    @Scheduled(fixedRate = 5000)
//    public void publish() {
//        log.debug("EventPublishSchedule execute.");
//        kafkaEventPublishService.publish();
//    }

}
